<?php
// +----------------------------------------------------------------------
// |  [ MAKE YOUR WORK EASIER]
// +----------------------------------------------------------------------
// | Copyright (c) 2003-2016 http://www.nbcc.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: fangrenfu <fangrenfu@126.com> 2016/6/19 10:20
// +----------------------------------------------------------------------

namespace app\common\access;

use think\Db;
use think\Exception;

/**获取各种对象的关键属性
 * Class Item
 * @package app\common\access
 */
class Item {
   //获取教师
    public static function getTeacherItem($teacherno,$alert=true){
        $result=null;
        $condition=null;
        $condition['teacherno']=$teacherno;
        $data=Db::table('teachers')
            ->join('schools','schools.school=teachers.school')->where($condition)->field('rtrim(teachers.name) as teachername,teacherno,rtrim(schools.name) schoolname')->select();
        if(!is_array($data)||count($data)!=1) {
            if($alert)
                throw new Exception('teacherno:' . $teacherno, MyException::ITEM_NOT_EXISTS);
        }
        else
            $result=$data[0];
        return $result;
    }
}